package huhx.linux.com.kotlinlearn.base;

import android.app.Activity;
import android.app.Application;
import android.content.Context;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by huhx on 2018-03-17 下午 11:14.
 */

public class BaseApplication extends Application {

    private List<Activity> activityList;
    private static Context _context;
    private String packageName;

    @Override
    public void onCreate() {
        super.onCreate();
        _context = getApplicationContext();
        activityList = new ArrayList<>();
        packageName = getPackageName();

    }

    public static BaseApplication getContext() {
        return (BaseApplication) _context;
    }

    public static void showToast(String message, int duration, int icon, int gravity) {
        Context context = _context;
        if (context != null){

        }
//            SimpleToast.show(context, message, gravity, duration);
    }

    // ------------------------------activity管理-----------------------//

    // activity管理：从列表中移除activity，按回退建时可单独调用
    public void removeActivity(Activity activity) {
        if (activityList.contains(activity))
            activityList.remove(activity);
    }

    // activity管理：添加activity到列表
    public void addActivity(Activity actClass) {
        if (!activityList.contains(actClass))
            activityList.add(actClass);
    }

    // activity管理：结束所有activity
    public void finishAllActivity() {
        for (Activity activity : activityList) {
            if (null != activity) {
                activity.finish();
            }
        }
    }
}
